package com.zephyr.vchcenter.bpm.decision;

import org.apache.log4j.Logger;

import com.hiaward.bpm.context.ServiceContext;
import com.hiaward.bpm.exception.ParameterException;
import com.hiaward.bpm.exception.RuleException;
import com.hiaward.bpm.exception.ServiceException;
import com.hiaward.bpm.rule.Decision;
import com.zephyr.vchcenter.bean.Voucher;
import com.zephyr.vchcenter.dao.IBaseDao;
import com.zephyr.vchcenter.helper.SpringHelper;

public class AuditVerifyDecisionHandler extends Decision {
	private final Logger log=Logger.getLogger(AuditVerifyDecisionHandler.class);
	@Override
	public void exceptionHandle(ServiceContext arg0) {

	}
	@Override
	public String make(ServiceContext arg0) throws RuleException,
			ServiceException, ParameterException {
		String vchsid=(String)arg0.getInputParameterValue("vchsid");
		IBaseDao dao = (IBaseDao) SpringHelper.getBean("baseDao");
		Voucher voucher=(Voucher)dao.findById("Voucher", vchsid);
		String acctype=voucher.getAcctype();
		String chkstate=voucher.getChkstate();
		String transition=null;
		if("2".equals(acctype)&&"1".equals(chkstate)){
			log.debug("复核未通过 转回财政户审票");
			voucher.setChkstate("5");
			transition="to financialAudit";
		}
		if("1".equals(acctype)&&"1".equals(chkstate)){
			log.debug("复核未通过 转回非财政户审票");
			voucher.setChkstate("1");
			transition="to audit";
			
		}
		if("4".equals(chkstate)){
			log.debug("复核通过 转向join节点");
			transition="to join1";
			
		}
		dao.saveOrUpdate(voucher);
		return transition;
	}

}
